﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NCP.Recruiting.Domain.Aggregates.Companies;
using NCP.Recruiting.Repository.SqlServer.Data;
using NCP.Recruiting.Repository.SqlServer.UnitOfWork;

namespace NCP.Recruiting.Repository.SqlServer.Repositories {
    public class CompanyRepository : Repository<Company>, ICompanyRepository {
        public CompanyRepository(MainBCUnitOfWork unitOfWork)
            : base(unitOfWork) {

        }

        public Company GetCompanyByName(string username) {
            var currentUnitOfWork = this.UnitOfWork as MainBCUnitOfWork;

            var set = currentUnitOfWork.CreateSet<Company>();

            //return set.Include("Jobpositions")
            return set.Where(c => c.Username == username)
                     .SingleOrDefault();

        }

        public override Company Get(Guid id) {
            if (id != Guid.Empty) {
                var currentUnitOfWork = this.UnitOfWork as MainBCUnitOfWork;

                var set = currentUnitOfWork.CreateSet<Company>();

                return set
                    //.Include("Jobpositions")
                    //.Include("Contracts")
                    .Where(c => c.Id == id)
                    .SingleOrDefault();
            }

            return null;

        }
    }
}
